package com.shanzmoo.admin.web.store;

import com.shanzmoo.admin.domain.dto.StoreStockAllotBillCancelDTO;
import com.shanzmoo.admin.domain.dto.StoreStockAllotBillSaveDTO;
import com.shanzmoo.admin.domain.dto.StoreStockAllotBillUpdateDTO;
import com.shanzmoo.admin.manager.store.StoreStockAllotBillManager;
import com.shanzmoo.base.bean.SResponse;
import com.shanzmoo.db.store.entity.query.StoreStockAllotBillQuery;
import com.shanzmoo.db.store.entity.vo.StoreStockAllotBillVO;
import com.shanzmoo.base.bean.PageRespBase;
import com.shanzmoo.base.bean.SHttpResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 仓库调拨单 控制层
 *
 * @author Gzhao 2021-03-11
 */
@Api(tags = "仓库-调拨单")
@RestController
@RequestMapping("/store/stock-allot-bill")
public class StoreStockAllotBillController {

    @Autowired
    private StoreStockAllotBillManager storeStockAllotBillManager;

    @ApiOperation(value = "分页列表")
    @PostMapping("/pageList")
    public SHttpResponse<PageRespBase<StoreStockAllotBillVO>> pageList(@Valid @RequestBody StoreStockAllotBillQuery query) {
        PageRespBase<StoreStockAllotBillVO> pageList = storeStockAllotBillManager.queryPage(query);
        return SHttpResponse.ok(pageList);
    }

    @ApiOperation(value = "添加")
    @PostMapping("/add")
    public SHttpResponse<Boolean> add(@Valid @RequestBody StoreStockAllotBillSaveDTO saveDto) {
        storeStockAllotBillManager.saveAllotBill(saveDto);
        return SHttpResponse.ok(Boolean.TRUE);
    }

    @ApiOperation(value = "修改")
    @PostMapping("/update")
    public SHttpResponse<Boolean> update(@Valid @RequestBody StoreStockAllotBillUpdateDTO updateDto) {
        storeStockAllotBillManager.saveAllotBill(updateDto);
        return SHttpResponse.ok(Boolean.TRUE);
    }

    @ApiOperation(value = "作废")
    @PostMapping("/cancel")
    public SHttpResponse<Boolean> cancel(@Valid @RequestBody StoreStockAllotBillCancelDTO cancelDTO) {
        SResponse<Boolean> re = storeStockAllotBillManager.cancel(cancelDTO);
        return SHttpResponse.transform(re);
    }

    @ApiOperation(value = "审核通过")
    @GetMapping("/examine")
    public SHttpResponse<Boolean> examine(@RequestParam(value = "id") Integer id) {
        SResponse<Boolean> re = storeStockAllotBillManager.examine(id);
        return SHttpResponse.transform(re);
    }

    @ApiOperation(value = "详情")
    @GetMapping("/info")
    public SHttpResponse<StoreStockAllotBillVO> getInfo(@RequestParam(value = "id") Integer id) {
        SResponse<StoreStockAllotBillVO> re = storeStockAllotBillManager.getInfo(id);
        return SHttpResponse.transform(re);
    }

 }
